// 组件市场里面所有组件状态的仓库
import { defineStore } from 'pinia';
import { defaultStatusMap } from '@/configs/DefaultStatus/DefaultStatusMap.js';
import {
  setTextStatus,
  addOption,
  removeOption,
  setPosition,
  setFontSize,
  setFontWeight,
  setFontItalic,
  setFontColor,
  setOptionLink,
  addPicOption,
  setTextType,
  setOptionIsUse,
  setDateTime,
} from './actions';

import { updateInitStatusBeforeAdd } from '@/utils';

const initArray = [
  'personal-info-name',
  'personal-info-id',
  'personal-info-tel',
  'personal-info-wechat',
  'personal-info-qq',
  'personal-info-email',
  'personal-info-address',
  'personal-info-gender',
  'personal-info-age',
  'personal-info-education',
  'personal-info-career',
  'personal-info-birth',
  'personal-info-collage',
  'personal-info-major',
  'personal-info-industry',
  'personal-info-company',
  'personal-info-position',
];

const initObj = {};

initArray.forEach((key) => {
  const defaultStatus = defaultStatusMap[key]();
  updateInitStatusBeforeAdd(defaultStatus, key);
  initObj[key] = defaultStatus;
});

export const useMaterialStore = defineStore('materialStore', {
  state: () => ({
    // 当前组件
    currentMaterialCom: 'single-select',
    // 记录所有的业务组件
    coms: {
      'single-select': defaultStatusMap['single-select'](),
      'multi-select': defaultStatusMap['multi-select'](),
      'option-select': defaultStatusMap['option-select'](),
      'single-pic-select': defaultStatusMap['single-pic-select'](),
      'multi-pic-select': defaultStatusMap['multi-pic-select'](),
      'text-note': defaultStatusMap['text-note'](),
      'text-input': defaultStatusMap['text-input'](),
      'rate-score': defaultStatusMap['rate-score'](),
      'date-time': defaultStatusMap['date-time'](),

      'personal-info-name': initObj['personal-info-name'],
      'personal-info-id': initObj['personal-info-id'],
      'personal-info-tel': initObj['personal-info-tel'],
      'personal-info-wechat': initObj['personal-info-wechat'],
      'personal-info-qq': initObj['personal-info-qq'],
      'personal-info-email': initObj['personal-info-email'],
      'personal-info-address': initObj['personal-info-address'],
      'personal-info-gender': initObj['personal-info-gender'],
      'personal-info-age': initObj['personal-info-age'],
      'personal-info-education': initObj['personal-info-education'],
      'personal-info-career': initObj['personal-info-career'],
      'personal-info-birth': initObj['personal-info-birth'],
      'personal-info-collage': initObj['personal-info-collage'],
      'personal-info-major': initObj['personal-info-major'],
      'personal-info-industry': initObj['personal-info-industry'],
      'personal-info-company': initObj['personal-info-company'],
      'personal-info-position': initObj['personal-info-position'],
    },
  }),
  actions: {
    updateCurrentMaterialCom(payload) {
      this.currentMaterialCom = payload;
    },
    setTextStatus,
    addOption,
    removeOption,
    setPosition,
    setFontSize,
    setFontWeight,
    setFontItalic,
    setFontColor,
    setOptionLink,
    addPicOption,
    setTextType,
    setOptionIsUse,
    setDateTime,
  },
});
